#ifndef _OBJET_IMG_H
#define _OBJET_IMG_H

#include <fstream>
#include <iostream>
#include <string>
#include "Objet3D.h"

using namespace std;

class ObjetIMG : public Objet3D 
{
 private :

 public :
  gl_texture_t *Tex;

  void charger()
  { 
    glEnable(GL_TEXTURE_2D);
    if(_texname!=""){
      Tex = ReadPNGFromFile(_texname.c_str());
      glGenTextures(1, &Tex->id);

      glBindTexture(GL_TEXTURE_2D,Tex->id);

      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      glTexImage2D (GL_TEXTURE_2D, 
		    0, 
		    Tex->internalFormat, 
		    Tex->width, 
		    Tex->height, 
		    0, 
		    Tex->format, 
		    GL_UNSIGNED_BYTE, 
		    Tex->texels);
    }
  }

  void dessiner(float scale = 1)
  { 
    glDisable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST); 
    glCullFace(GL_BACK);
    glEnable(GL_TEXTURE_2D);
    glColor3ub(255,255,255);
    glPushMatrix();

    glTranslatef(_posX, _posY, _posZ);
    glRotatef(_angleX,1.,0.,0.); 
    glRotatef(_angleY,0.,1.,0.); 
    glRotatef(_angleZ,0.,0.,1.);

    glColor3ub(255,255,255);
    glBindTexture(GL_TEXTURE_2D,Tex->id);

    glBegin(GL_QUADS);
    glTexCoord2d(0,1);  glVertex3d(10,10,10);
    glTexCoord2d(0,0);  glVertex3d(10,10,-10);
    glTexCoord2d(1,0);  glVertex3d(-10,10,-10);
    glTexCoord2d(1,1);  glVertex3d(-10,10,10);
   
    glEnd();
	
    glDisable(GL_TEXTURE_2D);  

    glPopMatrix();
    
    glEnable(GL_LIGHTING);
    }
 
};

#endif
